package com.wyx.calendar_test

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.haibin.calendarview.Calendar
import com.haibin.calendarview.CalendarView

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        var mCalendarView=findViewById<CalendarView>(R.id.calendarView)

        val year: Int = mCalendarView.getCurYear()
        val month: Int = mCalendarView.getCurMonth()

        val map: MutableMap<String, Calendar> = HashMap()
        for (y in 1997..2081) {
            for (m in 1..12) {
                map[getSchemeCalendar(y, m, 1, -0xbf24db, "假").toString()] = getSchemeCalendar(y, m, 1, -0xbf24db, "假")
                map[getSchemeCalendar(y, m, 2, -0x196ec8, "游").toString()] = getSchemeCalendar(y, m, 2, -0x196ec8, "游")
                map[getSchemeCalendar(y, m, 3, -0x20ecaa, "事").toString()] = getSchemeCalendar(y, m, 3, -0x20ecaa, "事")
                map[getSchemeCalendar(y, m, 4, -0x5533bc, "车").toString()] = getSchemeCalendar(y, m, 4, -0x5533bc, "车")
                map[getSchemeCalendar(y, m, 5, -0x43ec10, "驾").toString()] = getSchemeCalendar(y, m, 5, -0x43ec10, "驾")
                map[getSchemeCalendar(y, m, 6, -0xabdd9f, "记").toString()] = getSchemeCalendar(y, m, 6, -0xabdd9f, "记")
                map[getSchemeCalendar(y, m, 7, -0xb5b42e, "会").toString()] = getSchemeCalendar(y, m, 7, -0xb5b42e, "会")
                map[getSchemeCalendar(y, m, 8, -0x196ec8, "车").toString()] = getSchemeCalendar(y, m, 8, -0x196ec8, "车")
                map[getSchemeCalendar(y, m, 9, -0xabdd9f, "考").toString()] = getSchemeCalendar(y, m, 9, -0xabdd9f, "考")
                map[getSchemeCalendar(y, m, 10, -0x7850a6, "记").toString()] = getSchemeCalendar(y, m, 10, -0x7850a6, "记")
                map[getSchemeCalendar(y, m, 11, -0xbf24db, "会").toString()] = getSchemeCalendar(y, m, 11, -0xbf24db, "会")
                map[getSchemeCalendar(y, m, 12, -0x325e51, "游").toString()] = getSchemeCalendar(y, m, 12, -0x325e51, "游")
                map[getSchemeCalendar(y, m, 13, -0x6a50e6, "事").toString()] = getSchemeCalendar(y, m, 13, -0x6a50e6, "事")
                map[getSchemeCalendar(y, m, 14, -0xcc5523, "学").toString()] = getSchemeCalendar(y, m, 14, -0xcc5523, "学")
                map[getSchemeCalendar(y, m, 15, -0xe500e6, "码").toString()] = getSchemeCalendar(y, m, 15, -0xe500e6, "码")
                map[getSchemeCalendar(y, m, 16, -0xdd5351, "驾").toString()] = getSchemeCalendar(y, m, 16, -0xdd5351, "驾")
                map[getSchemeCalendar(y, m, 17, -0x665906, "校").toString()] = getSchemeCalendar(y, m, 17, -0x665906, "校")
                map[getSchemeCalendar(y, m, 18, -0x196ec8, "车").toString()] = getSchemeCalendar(y, m, 18, -0x196ec8, "车")
                map[getSchemeCalendar(y, m, 19, -0xbf24db, "码").toString()] = getSchemeCalendar(y, m, 19, -0xbf24db, "码")
                map[getSchemeCalendar(y, m, 20, -0x196ec8, "火").toString()] = getSchemeCalendar(y, m, 20, -0x196ec8, "火")
                map[getSchemeCalendar(y, m, 21, -0xbf24db, "假").toString()] = getSchemeCalendar(y, m, 21, -0xbf24db, "假")
                map[getSchemeCalendar(y, m, 22, -0x665906, "记").toString()] = getSchemeCalendar(y, m, 22, -0x665906, "记")
                map[getSchemeCalendar(y, m, 23, -0xcc5523, "假").toString()] = getSchemeCalendar(y, m, 23, -0xcc5523, "假")
                map[getSchemeCalendar(y, m, 24, -0xbf24db, "校").toString()] = getSchemeCalendar(y, m, 24, -0xbf24db, "校")
                map[getSchemeCalendar(y, m, 25, -0xe500e6, "假").toString()] = getSchemeCalendar(y, m, 25, -0xe500e6, "假")
                map[getSchemeCalendar(y, m, 26, -0xbf24db, "议").toString()] = getSchemeCalendar(y, m, 26, -0xbf24db, "议")
                map[getSchemeCalendar(y, m, 27, -0x6a50e6, "假").toString()] = getSchemeCalendar(y, m, 27, -0x6a50e6, "假")
                map[getSchemeCalendar(y, m, 28, -0xbf24db, "码").toString()] = getSchemeCalendar(y, m, 28, -0xbf24db, "码")
            }
        }

        //28560 数据量增长不会影响UI响应速度，请使用这个API替换

        //28560 数据量增长不会影响UI响应速度，请使用这个API替换
        mCalendarView.setSchemeDate(map)
//        mCalendarView.setAllMode()

    }

    private fun getSchemeCalendar(year: Int, month: Int, day: Int, color: Int, text: String): Calendar {
        val calendar = Calendar()
        calendar.setYear(year)
        calendar.setMonth(month)
        calendar.setDay(day)
        calendar.setSchemeColor(color) //如果单独标记颜色、则会使用这个颜色
        calendar.setScheme(text)
        return calendar
    }
}
